home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 7_10.lha / 7_10 / qh_get.c < prev    next >
Text File  |  1993-08-08  |  1KB  |  54 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <process.h>
  6. include <debug.h>    /* DELETE */
  7. / Return an object from the head of the queue.
  8. / If necessary, pause and loop
  9. / until one becomes available.
  10. rocess_object *queue_head::get()
  11.  
  12.    if (debug) /*DELETE*/ cerr << "queue_head" << this << "::get()\n";
  13.    register process_queue *q = qh_queue;
  14.  
  15.    while (q->q_count == 0)
  16. switch (qh_mode)
  17.     {
  18.     case Q_WMODE:
  19.     this_process()->pause(this);
  20.     break;
  21.  
  22.     case Q_EMODE:
  23.     error("queue_head::get(): empty queue");
  24.     break;
  25.  
  26.     case Q_ZMODE:
  27.     if (debug) /*DELETE*/ cerr << "<<<< queue_head" << this << "::get() <- 0\n";
  28.     return 0;
  29.     }
  30.  
  31.    process_object *last = q->q_last;
  32.    process_object *first = last->po_next;
  33.  
  34.    // the queue was full
  35.    int wasfull = (q->q_count-- == q->q_max);
  36.  
  37.    // is the queue now empty
  38.    if (q->q_count == 0)
  39. first->po_next = q->q_last = 0;
  40.  
  41.    // does the queue still have some objects on it
  42.    else
  43.        {
  44. last->po_next = first->po_next;
  45. first->po_next = 0;
  46. }
  47.  
  48.    if (wasfull && q->q_tail)
  49. q->q_tail->alert();
  50.  
  51.    if (debug) /*DELETE*/ cerr << "<<<< queue_head" << this << "::get()\n";
  52.    return first;
  53.  
  54.